import socket 

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
addr = ('', 50002)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(addr)
print 'bind on port: ', 50002
sock.listen(5)

while True:
  conn, address=sock.accept() 
  print 'accept a connect from', address
  while True:
    buff=conn.recv(8192)
    if len(buff) ==0:
		  break;
    print "recv data from node app",buff
    if buff=='1':
      conn.send('1 too')
    elif buff=='2':
      conn.send('2 too')
  conn.close()
